﻿using System;
using Data;
using Vote;
using System.Linq;
using System.Text;

namespace VoteConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Data.Data.Add();
            string Account,Password,Nickname;
            User user=null;
            Console.WriteLine(" 投票系统");
            Console.WriteLine("==========");
            while(user== null)
            {
                Console.WriteLine("请输入帐号:");
                Account=Console.ReadLine();
                Console.WriteLine("请输入密码");
                Password = Console.ReadLine();
                user = Data.Data.Users.SingleOrDefault(p=>p.Account.Equals(Account)&&p.Password.Equals(Password));
                if(user==null)
                {
                    Console.WriteLine("查无此人，请重新输入");
                }
            }
            int select = 0;
            while (select!=3)
            {
                Console.WriteLine("你好" +user.Nickname);
                Console.WriteLine("请选择操作选项");
                Console.WriteLine("1:投票");
                Console.WriteLine("2:查看投票统计");
                Console.WriteLine("3:退出");
            
                Operation operation = new Operation();
                select = int.Parse(Console.ReadLine());
                if (select == 1)
                {
                    operation.Voting(Data.Data.Questions, user);
                }
                else if (select == 2)
                {
                    operation.Examine(Data.Data.Questions);
                }
                else if (select == 3)
                    break;
                else
                {
                    Console.WriteLine("暂无此功能，请重新输入");
                    select = 0;
                }
                

            }
        }
    }
}
